home *** CD-ROM | disk | FTP | other *** search
- unit ntc_server_search;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Variants,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- ExtCtrls,
- StdCtrls,
- Buttons,
- inifiles,
-
- ntc_server_object,
- ntc_server_form;
-
- const
- default_height=240;
- default_width=320;
- default_height_part=20;
- default_width_part=20;
- default_seconds=30;
- default_timeout=2000;
-
- type
- Tscope_search = class(TForm)
- search_panel: TPanel;
- dimensions_group: TGroupBox;
- seconds_edit: TEdit;
- seconds_label: TLabel;
- width_label: TLabel;
- height_label: TLabel;
- cycler_group: TGroupBox;
- timeout_edit: TEdit;
- timeout_label: TLabel;
- out_panel: TPanel;
- search_timer: TTimer;
- out_label: TLabel;
- in_panel: TPanel;
- in_label: TLabel;
- clock_panel: TPanel;
- clock_label: TLabel;
- counter_panel: TPanel;
- counter_label: TLabel;
- out_button: TSpeedButton;
- in_button: TSpeedButton;
- clock_button: TSpeedButton;
- counter_button: TSpeedButton;
- width_edit: TEdit;
- height_edit: TEdit;
- reset_group: TGroupBox;
- reset_panel: TPanel;
- reset_label: TLabel;
- reset_button: TSpeedButton;
- stop_panel: TPanel;
- stop_button: TSpeedButton;
- stop_label: TLabel;
- { end test code *** }
-
- { form handlling }
- procedure FormCreate(
- Sender: TObject);
-
- procedure form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
-
- procedure disable_panel;
- procedure enable_panel;
-
- { configuration }
- procedure save_settings;
-
- procedure load_settings;
-
- procedure flip_buttons(
- toggle:boolean);
-
- procedure counter(
- t:string);
-
- { events }
- procedure out_buttonClick(
- Sender: TObject);
-
- procedure clock_buttonClick(
- Sender: TObject);
-
- procedure counter_buttonClick(
- Sender: TObject);
-
- procedure in_buttonClick(
- Sender: TObject);
-
- procedure reset_buttonClick(
- Sender: TObject);
-
- procedure stop_buttonClick(
- Sender: TObject);
-
- procedure FormShow(
- Sender:TObject);
-
- procedure adjust;
-
- procedure check_activate(
- Sender: TObject);
-
- { timer }
- procedure enable_timer;
- procedure disable_timer;
- procedure poll_scope;
-
- procedure search_timerTimer(
- Sender: TObject);
-
- procedure width_editChange(
- Sender: TObject);
-
- procedure height_editChange(
- Sender: TObject);
-
- procedure seconds_editEnter(
- Sender: TObject);
- procedure timeout_editChange(Sender: TObject);
-
- private
- { Private declarations }
- dont_reset:boolean;
- public
- { Public declarations }
- timeout_interval:integer;
- height_part,
- width_part,
- seconds_in_pixel:double;
- camera_height,
- camera_width:integer;
- camera_height_part,
- camera_width_part:double;
- { moving }
- window_height,
- window_width:integer;
- { configuration }
- dimensions:dimensions_record;
-
- { events }
- procedure check_visible_and_show_hide(
- sender:tobject);
-
- procedure hide_form;
- procedure show_form;
- end;
-
- var
- scope_search: Tscope_search;
-
- implementation
-
- uses
- ntc_server_network,
- ntc_server_info,
- ntc_server_control,
- ntc_server_config,
- ntc_server_comms;
-
- {$R *.dfm}
- {$R icons.res}
-
- { -------------
- form handling
- ------------- }
-
- procedure Tscope_search.FormCreate(
- Sender: TObject);
- begin
- search_timer.Enabled:=false;
- flip_buttons(false);
- load_settings;
- dont_reset:=false;
- end;
-
- procedure tscope_search.form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
- begin
- canclose:=false;
- visible:=false;
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- end;
-
- procedure tscope_search.disable_panel;
- begin
- flip_buttons(false);
- out_button.enabled:=false;
- in_button.enabled:=false;
- clock_button.enabled:=false;
- counter_button.enabled:=false;
- end;
-
- procedure tscope_search.enable_panel;
- begin
- flip_buttons(true);
- out_button.enabled:=true;
- in_button.enabled:=true;
- clock_button.enabled:=true;
- counter_button.enabled:=true;
- end;
-
- procedure tscope_search.FormShow(
- Sender:TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- end;
-
- procedure tscope_search.adjust;
- begin
- with dimensions do
- begin
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- end;
- if visible then
- show;
- end;
-
- procedure tscope_search.check_visible_and_show_hide(
- sender:tobject);
- begin
- if visible then
- hide_form
- else
- show_form;
- scope.show_hide(sender,visible);
- end;
-
- procedure tscope_search.hide_form;
- begin
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- Visible:=false;
- end;
-
- procedure tscope_search.show_form;
- begin
- Visible:=true;
- end;
-
- procedure tscope_search.check_activate(
- Sender: TObject);
- begin
- scope.form_activate(scope_search,@dimensions);
- end;
-
- { ---------
- utilities
- --------- }
-
- procedure tscope_search.flip_buttons(
- toggle:boolean);
- begin
- dimensions_group.enabled:=toggle;
- cycler_group.enabled:=toggle;
- end;
-
- { -------------
- configuration
- ------------- }
-
- procedure tscope_search.load_settings;
- begin
- ini_file:=tinifile.create(application_path+'server.ini');
- with ini_file do
- begin
- dont_reset:=true;
- camera_height:=readinteger('search','window_height',default_height);
- camera_width:=readinteger('search','window_width',default_width);
- camera_height_part:=readfloat('search','height_part',default_height_part);
- camera_width_part:=readfloat('search','width_part',default_width_part);
- seconds_in_pixel:=readfloat('search','seconds_in_pixel',default_seconds);
- timeout_interval:=readinteger('search','timeout_interval',default_timeout);
- height_edit.text:=inttostr(camera_height);
- width_edit.text:=inttostr(camera_width);
- seconds_edit.text:=floattostr(seconds_in_pixel);
- timeout_edit.text:=inttostr(timeout_interval);
- { form }
- scope.get_dimensions(scope_search,@dimensions,'search',ini_file);
- left:=dimensions.form_left;
- top:=dimensions.form_top;
- visible:=readbool('search','visible',false);
- dont_reset:=false;
- end;
- ini_file.free;
- end;
-
- procedure tscope_search.save_settings;
- begin
- with ini_file do
- begin
- scope_network.send_message_check('reset_search');
- writeinteger('search','window_height',camera_height);
- writeinteger('search','window_width',camera_width);
- writefloat('search','height_part',camera_height_part);
- writefloat('search','width_part',camera_width_part);
- writefloat('search','seconds_in_pixel',seconds_in_pixel);
- writeinteger('search','interval_timeout',timeout_interval);
- { form }
- scope.find_vdu(scope_search,@dimensions);
- scope.write_dimensions(@dimensions,left,top,'search',ini_file);
- writebool('search','visible',visible);
- end;
- end;
-
- { ------
- events
- ------ }
-
- { ----------------------------
- move out to larger perimeter
- ---------------------------- }
-
- procedure Tscope_search.out_buttonClick(
- Sender: TObject);
- begin
- with scope_network do
- begin
- if not (send_message_check('break_out')=[exit_ok]) then
- scope_control.write_status_log('invalid response from server')
- else
- inc(frame_level);
- end;
- end;
-
- { -------------------
- move to inner frame
- ------------------- }
-
- procedure Tscope_search.in_buttonClick(
- Sender: TObject);
- begin
- with scope_network do
- if frame_level>0 then
- begin
- if not (send_message_check('fall_in')=[exit_ok]) then
- scope_control.write_status_log('invalid response from server')
- else
- dec(frame_level);
- end;
- end;
-
- procedure Tscope_search.counter(
- t:string);
- begin
- if scope_network.send_message_check('counter')>=[exit_ok] then
- enable_timer
- else
- scope_control.write_status_log('move failed');
- end;
-
- { ----------------------------
- move to next frame clockwise
- ---------------------------- }
-
- procedure Tscope_search.clock_buttonClick(
- Sender: TObject);
- begin
- if scope_network.send_message_check('clockwise')>=[exit_ok] then
- enable_timer
- else
- scope_control.write_status_log('move failed');
- end;
-
- { ---------------------------------
- move to next frame anti-clockwise
- --------------------------------- }
-
- procedure Tscope_search.counter_buttonClick(
- Sender: TObject);
- begin
- if scope_network.send_message_check('counter')>=[exit_ok] then
- enable_timer
- else
- scope_control.write_status_log('move failed');
- end;
-
- { -----------
- reset event
- ----------- }
-
- procedure Tscope_search.reset_buttonClick(
- Sender: TObject);
- begin
- if not dont_reset then
- begin
- scope_network.send_message_check('reset_search');
- disable_timer;
- end;
- end;
-
- { ----------
- stop event
- ---------- }
-
- procedure Tscope_search.stop_buttonClick(
- Sender: TObject);
- begin
- if not dont_reset then
- begin
- scope_network.send_message_check('reset_search');
- disable_timer;
- end;
- scope_control.stop_scope;
- end;
-
- { -----
- timer
- ----- }
-
- procedure tscope_search.enable_timer;
- begin
- scope_control.change_panel(false);
- search_timer.Interval:=timeout_interval;
- search_timer.enabled:=true;
- end;
-
- procedure tscope_search.disable_timer;
- begin
- search_timer.enabled:=false;
- scope_info.show_info;
- scope_control.moving_scope:=false;
- scope_control.change_panel(true);
- end;
-
- procedure tscope_search.poll_scope;
- var
- moving:boolean;
- begin
- with scope_network do
- if send_message_check('stopped')>=[exit_ok] then
- begin
- get_boolean('moving',moving);
- if not moving then
- begin
- scope_control.moving_scope:=false;
- disable_timer;
- end;
- end;
- end;
-
- procedure Tscope_search.search_timerTimer(
- Sender: TObject);
- begin
- if not scope_comms.response_timer.enabled then
- poll_scope;
- end;
-
- procedure overlap_change(
- var s:string;
- var def:double);
- var
- d:double;
- begin
- while (length(s)>0) and
- ((copy(s,length(s),1)>'9') or
- (copy(s,length(s),1)<'0')) do
- s:=copy(s,1,length(s)-1);
- if length(s)=0 then
- d:=20
- else
- d:=strtofloatdef(s,def);
- if (d>=0) and (d<100) then
- def:=d
- else
- s:=floattostr(def);
- s:=s+'%';
- end;
-
- procedure Tscope_search.width_editChange(
- Sender: TObject);
- begin
- if not dont_reset then
- scope_network.send_message_check('reset_search');
- end;
-
- procedure Tscope_search.height_editChange(
- Sender: TObject);
- begin
- if not dont_reset then
- scope_network.send_message_check('reset_search');
- end;
-
- procedure Tscope_search.seconds_editEnter(
- Sender: TObject);
- begin
- seconds_in_pixel:=strtofloatdef(seconds_edit.text,default_seconds);
- end;
-
- procedure Tscope_search.timeout_editChange(Sender: TObject);
- begin
- timeout_interval:=strtointdef(timeout_edit.text,2000);
- if timeout_interval<2000 then
- begin
- timeout_interval:=2000;
- timeout_edit.text:=inttostr(timeout_interval);
- end;
- end;
-
- end.
-